package com.qigao.mall.web.controller.app.user;

import com.qigao.mall.api.BillItemService;
import com.qigao.mall.commons.enums.Result;
import com.qigao.mall.commons.enums.ResultCode;
import com.qigao.mall.commons.po.UserInfo;
import com.qigao.mall.web.utils.RequestUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/app/billItem/")
@Api(tags = "APP费用项相关API" ,value = "APP费用项相关API")
public class AppBillItemController {
    private static Logger logger= LoggerFactory.getLogger(AppBillItemController.class);
    @Resource
    BillItemService tbBillItemService;



    @RequestMapping(value = "/calBenefitByProd/{prodSaleAmt}", method = RequestMethod.POST)
    @ApiOperation(value = "按照商品金额计算当前用户优惠金额", notes = "按照商品金额计算当前用户优惠金额")
    @ApiImplicitParam(name = "prodSaleAmt", value = "商品销售金额", required = true, dataType = "string", paramType = "path")
    public Result calBenefitByProd(@PathVariable("prodSaleAmt") String prodSaleAmt, HttpServletRequest request) {
        try {
            UserInfo userInfo=RequestUtils.getCurrentUser(request);
            return tbBillItemService.calBenefitByProd(userInfo.getUserType(),userInfo.getUserLevel(),prodSaleAmt);
        } catch (Exception e) {
            logger.error("按照商品金额计算当前用户优惠金额异常!{}", e);
            return Result.newError(ResultCode.FAIL);
        }
    }


}
